package huanzhao.erp.other.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MybatisPlus配置类
 *
 * @author April
 * 2024/7/25 下午4:36
 * @version 1.0
 */
@Configuration
// 扫描mapper接口
@MapperScan("huanzhao.erp.mapper")
public class MybatisPlusConfig {
    /**
     * 注册插件
     *
     * @return MybatisPlusInterceptor
     * 2024/7/25 下午4:39:17
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 添加乐观锁插件
        // interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());

        // 分页插件放在最后
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        // 设置分页上限
        paginationInnerInterceptor.setMaxLimit(1000L);
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        return interceptor;
    }
}
